package net.sf.google.talk.eclipse.views;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterGroup;

public class GroupFilter extends ViewerFilter {
	private String regex;

	public GroupFilter() {
		super();
	}

	@Override
	public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
		//		System.out.println("element: "+element);
		if (element instanceof RosterEntry) {
			final RosterEntry e = (RosterEntry) element;
			for (final RosterGroup g : e.getGroups()) {
				if (g.getName() != null && g.getName().matches(regex)) {
					return true;
				}
			}
		}
		return false;
	}

	public String getRegex() {
		return regex;
	}

	public void setRegex(final String regex) {
		this.regex = regex;
	}

}
